import Foundation

@MainActor
final class HomeViewModel: ObservableObject {
    @Published private(set) var popularDestinations: [Destination] = []
    @Published private(set) var isLoading: Bool = false
    @Published private(set) var errorMessage: String?

    private let destinationService: DestinationService

    init(destinationService: DestinationService) {
        self.destinationService = destinationService
    }

    func load() async {
        guard !isLoading else { return }
        isLoading = true
        errorMessage = nil
        do {
            popularDestinations = try await destinationService.fetchPopularDestinations()
        } catch {
            errorMessage = error.localizedDescription
        }
        isLoading = false
    }
}


